package com.example.binding_recyclerview.view;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ObservableArrayList;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.binding_recyclerview.R;
import com.example.binding_recyclerview.adapter.MyRecycleAdapter;
import com.example.binding_recyclerview.databinding.FragmentRecycBinding;
import com.example.binding_recyclerview.databinding.MyListItemBinding;
import com.example.binding_recyclerview.model.Student;
import com.example.binding_recyclerview.viewmodel.RecycleViewMoel;

import java.util.Objects;

/**
 */
public class RecycFragment extends Fragment {

    private FragmentRecycBinding recycBinding ;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        recycBinding = FragmentRecycBinding.inflate(inflater , container , false);

        //这是约束布局
        View view = recycBinding.getRoot();
        //我把约束布局传给adapter，让adapter可以修改布局中的数据
        view.setTag(recycBinding);
        RecycleViewMoel recycleViewMoel = new ViewModelProvider(this).get(RecycleViewMoel.class);
        recycBinding.setVm(recycleViewMoel);

        //绑定布局管理器
//        recycBinding.rv.setLayoutManager(new LinearLayoutManager(getContext()));
//        ObservableArrayList<Student> students = new RecycleViewMoel().getStudents();
//        //绑定适配器 这里是绑定了一个RecycleAdapter适配器
//        recycBinding.rv.setAdapter(new MyRecycleAdapter(students));
        //现在我手动绑定另外一种适配器 listAdapter  -- 算了后面再说吧

        return  view;
    }


}